import { BasicColumn, FormSchema } from '/@/components/Table';
import { getDictListApi, getDictDetailListApi } from '/@/api/sys/dict';
import { ButtonTypeEnum } from '/@/enums/sysEnum';

export const Permission = {
  IMPORT: 'gen.table.import',
  EDIT: 'gen.table.edit',
  DEL: 'gen.table.del',
  DOWNLOAD: 'gen.table.download',
};

export const columns: BasicColumn[] = [
  {
    title: '表名',
    dataIndex: 'tableName',
  },
  {
    title: '表前缀',
    dataIndex: 'tablePrefix',
  },
  {
    title: '实体类',
    dataIndex: 'className',
  },
  {
    title: '注释',
    dataIndex: 'tableComment',
  },
  {
    title: '作者',
    dataIndex: 'author',
  },
  {
    title: '包名',
    dataIndex: 'packageName',
  },
  {
    title: '模块名',
    dataIndex: 'moduleName',
  },
  {
    title: '功能名',
    dataIndex: 'functionName',
  },
  {
    title: '表单类型',
    dataIndex: 'formType',
  },
  {
    title: '表单布局',
    dataIndex: 'formLayout',
  },
  {
    title: '是否继承基类',
    dataIndex: 'extendBaseEntity',
  },
  {
    title: '创建时间',
    dataIndex: 'createAt',
  },
];

export const selectTableColumns: BasicColumn[] = [
  {
    title: '表名',
    dataIndex: 'tableName',
  },
  {
    title: '注释',
    dataIndex: 'tableComment',
  },
  {
    title: '创建时间',
    dataIndex: 'createAt',
  },
];

export const selectTableSearchFormSchema: FormSchema[] = [
  {
    field: 'tableName',
    label: '表名',
    component: 'Input',
    colProps: { span: 12 },
  },
];

export const searchFormSchema: FormSchema[] = [
  {
    field: 'tableName',
    label: '表名',
    component: 'Input',
    colProps: { span: 6 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'tableName',
    label: '表名',
    component: 'Input',
    dynamicDisabled: true,
  },
  {
    field: 'tableComment',
    label: '注释',
    component: 'Input',
    rules: [
      { required: true, message: '请填写注释' },
      { max: 100, message: '注释最多100字' },
    ],
  },
  {
    field: 'author',
    label: '作者',
    component: 'Input',
    rules: [
      { required: true, message: '请填写作者' },
      { max: 100, message: '作者最多100字' },
    ],
  },
  {
    field: 'tablePrefix',
    label: '表前缀',
    component: 'Input',
    rules: [{ max: 100, message: '表前缀最多100字' }],
  },
  {
    field: 'className',
    label: '实体类名称',
    component: 'Input',
    rules: [
      { required: true, message: '请填写实体类名称' },
      { max: 100, message: '实体类名称最多100字' },
    ],
  },
  {
    field: 'packageName',
    label: '包名',
    component: 'Input',
    rules: [
      { required: true, message: '请填写包名' },
      { max: 100, message: '包名最多100字' },
    ],
  },
  {
    field: 'moduleName',
    label: '模块名',
    component: 'Input',
    rules: [
      { required: true, message: '请填写模块名' },
      { max: 100, message: '模块名最多100字' },
    ],
  },
  {
    field: 'functionName',
    label: '功能名',
    component: 'Input',
    rules: [
      { required: true, message: '请填写功能名' },
      { max: 100, message: '功能名最多100字' },
    ],
  },
  {
    field: 'formType',
    label: '表单类型',
    component: 'ApiRadioGroup',
    helpMessage: '大型表单推荐使用抽屉，小型表单推荐使用弹窗',
    componentProps: {
      api: getDictDetailListApi,
      params: {
        code: 'form_type',
      },
      isBtn: true,
      immediate: true,
    },
  },
  {
    field: 'formLayout',
    label: '表单布局',
    component: 'ApiRadioGroup',
    componentProps: {
      api: getDictDetailListApi,
      params: {
        code: 'form_layout',
      },
      isBtn: true,
      immediate: true,
    },
  },
  {
    field: 'extendBaseEntity',
    label: '继承基类',
    component: 'ApiRadioGroup',
    helpMessage: '表中拥有deleted、create_at、create_by、update_at、update_by五个字段时继承基类，缺少任一字段时不能继承基类',
    componentProps: {
      api: getDictDetailListApi,
      params: {
        code: 'yes_no',
      },
      isBtn: true,
    },
  },
  {
    field: 'buttonTypes',
    label: '功能选项',
    component: 'CheckboxGroup',
    helpMessage: ['请根据业务要求选择需要生成的功能，一般生成新增、修改、删除、查询、详情五个功能', '中间表一般不需要生成功能，未生成任何功能的将不会生成Controller文件和前端代码'],
    componentProps: {
      options: [
        { label: '新增', value: ButtonTypeEnum.ADD },
        { label: '删除', value: ButtonTypeEnum.DEL },
        { label: '修改', value: ButtonTypeEnum.EDIT },
        { label: '查询', value: ButtonTypeEnum.QUERY },
        { label: '详情', value: ButtonTypeEnum.DETAIL },
        { label: '集合', value: ButtonTypeEnum.LIST },
        { label: '导入', value: ButtonTypeEnum.IMPORTS },
        { label: '导出', value: ButtonTypeEnum.EXPORTS },
      ],
    },
  },
];

export const tableFieldcolumns: BasicColumn[] = [
  {
    title: '列名',
    dataIndex: 'columnName',
    fixed: 'left',
  },
  {
    title: '列类型',
    dataIndex: 'columnType',
  },
  {
    title: '字段名称',
    dataIndex: 'fieldName',
    edit: true,
    editRule: true,
  },
  {
    title: '字段类型',
    dataIndex: 'fieldType',
    edit: true,
    editRule: true,
    editComponent: 'Select',
    editComponentProps: {
      options: [
        {
          label: 'String',
          value: 0,
        },
        {
          label: 'Integer',
          value: 1,
        },
        {
          label: 'Long',
          value: 2,
        },
        {
          label: 'BigDecimal',
          value: 3,
        },
        {
          label: 'LocalDate',
          value: 4,
        },
        {
          label: 'LocalDateTime',
          value: 5,
        },
      ],
    },
  },
  {
    title: '类型包名',
    dataIndex: 'packageName',
    edit: true,
    editRule: true,
  },
  {
    title: '是否主键',
    dataIndex: 'primaryPk',
    edit: true,
    editRule: true,
    editComponent: 'RadioButtonGroup',
    editComponentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    title: '是否表单项',
    dataIndex: 'formItem',
    edit: true,
    editRule: true,
    editComponent: 'RadioButtonGroup',
    editComponentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    title: '是否必填',
    dataIndex: 'formRequired',
    edit: true,
    editComponent: 'RadioButtonGroup',
    editComponentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    title: '表单类型',
    dataIndex: 'formType',
    edit: true,
    editComponent: 'Select',
    editComponentProps: {
      options: [
        {
          label: '文本框',
          value: 0,
        },
        {
          label: '文本域',
          value: 1,
        },
        {
          label: '数字框',
          value: 2,
        },
        {
          label: '选择框',
          value: 3,
        },
        {
          label: '日期选择框',
          value: 4,
        },
        {
          label: '多选框',
          value: 5,
        },
        {
          label: '单选框',
          value: 6,
        },
      ],
    },
  },
  {
    title: '是否列表项',
    dataIndex: 'gridItem',
    edit: true,
    editRule: true,
    editComponent: 'RadioButtonGroup',
    editComponentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    title: '支持查询',
    dataIndex: 'queryItem',
    edit: true,
    editRule: true,
    editComponent: 'RadioButtonGroup',
    editComponentProps: {
      options: [
        {
          label: '是',
          value: 0,
        },
        {
          label: '否',
          value: 1,
        },
      ],
    },
  },
  {
    title: '查询方式',
    dataIndex: 'queryType',
    edit: true,
    editComponent: 'Select',
    editComponentProps: {
      options: [
        {
          label: 'Equal',
          value: 0,
        },
        {
          label: 'Like',
          value: 1,
        },
      ],
    },
  },
  {
    title: '查询表单类型',
    dataIndex: 'queryFormType',
    edit: true,
    editComponent: 'Select',
    editComponentProps: {
      options: [
        {
          label: '文本框',
          value: 0,
        },
        {
          label: '文本域',
          value: 1,
        },
        {
          label: '数字框',
          value: 2,
        },
        {
          label: '选择框',
          value: 3,
        },
        {
          label: '日期选择框',
          value: 4,
        },
        {
          label: '多选框',
          value: 5,
        },
        {
          label: '单选框',
          value: 6,
        },
      ],
    },
  },
  {
    title: '数据字典',
    dataIndex: 'dictCode',
    edit: true,
    editComponent: 'ApiSelect',
    editComponentProps: {
      api: getDictListApi,
      labelField: 'title',
      valueField: 'code',
    },
  },
];
